package com.example.text.Adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.example.text.R;
import com.example.text.mode_list;

import java.util.List;

public class Recyler_Adapter extends RecyclerView.Adapter<Recyler_Adapter.MyHolder> {
    private List<mode_list> lists;

    public Recyler_Adapter(List<mode_list> lists) {
        this.lists = lists;
    }

    @NonNull
    @Override
    public MyHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view= LayoutInflater.from(parent.getContext()).inflate(R.layout.mode_list,parent,false);
        MyHolder holder=new MyHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(@NonNull MyHolder holder, int position) {
        mode_list mode_list = lists.get(position);
        holder.img.setImageResource(mode_list.getImg());
        holder.title.setText(mode_list.getTitle());
        holder.content.setText(mode_list.getContent());
    }

    @Override
    public int getItemCount() {
        return lists.size();
    }
    class MyHolder extends RecyclerView.ViewHolder{
        ImageView img;
        TextView title;
        TextView content;

        public MyHolder(@NonNull View v) {
            super(v);
           img = v.findViewById(R.id.img);
           title=v.findViewById(R.id.title);
           content=v.findViewById(R.id.content);
        }
    }
}
